﻿using Ionic.Zip;
using LogsDownload.Models;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace LogsDownload.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            Debug.WriteLine("hello!");
            return View();
        }

        public ActionResult ListOfLogs()
        {
            List<EventLog> model;
            model = new LogFiles().getLogs();
            return View(model);
        }


        public ActionResult DownloadLogWithName(string id) //in this action we should take the request with parameter-name of the logfile
        { //(write in routeconfig?)
            string partpath = String.Concat("C:/", id); //C:/ is just an example of pysical path to file
            string file_path = String.Concat(partpath, ".evtx"); //got full path with concrete logfile name
            string file_type = "application/octet-stream"; //type of evt file
            string file_name = String.Concat(id, ".evtx"); //give the saving file name of downloading logfile
            return File(file_path, file_type, file_name); //download file
        }

        public FileResult DownloadLogsFromDirectoryAsZipFile()
        {
            string[] info =  LogFiles.getPathOfZipFile(); 


            string partpath = info[0]; //C:/ is just an example of pysical path to file
            string file_path = String.Concat(partpath, info[1]); //got full path with concrete logfile name
            string file_type = "application/octet-stream"; //type of evt file
            string file_name = info[1]; //give the saving file name of downloading logfile
            return File(file_path, file_type, file_name); //download file

        }

        
    }
}

